﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Spore.Validator
{
    /// <summary>
    /// 最小值验证器,验证字段大于或等于最小值
    /// </summary>
   public class ValidatorMinValue:ValidatorBase
    {
         private double minValue;
        /// <summary>       
        /// </summary>        
        /// <param name="errMsg">验证不通过时的错误信息</param>
        public ValidatorMinValue(double minValue,string errMsg)
        {
            this.minValue = minValue;
            this.ErrorMessage = errMsg;
        }
        public ValidatorMinValue(int minValue)
        {
            this.minValue = minValue;
            this.ErrorMessage = " 不能小于" + minValue.ToString();
        }

        /// <summary>
        ///验证内容为双精度型
        /// </summary>
        /// <param name="controlToValidate">要验证的控件</param>
        /// <returns></returns>
        public override bool IsValid(Control controlToValidate)
        {
            string content = controlToValidate.Text;
            double tmp;
           if( double.TryParse(content, out tmp))
            return tmp >= minValue;
           return false;
        }
    }
}
